package com.chaodriod.common.activity;

import android.app.Activity;
import android.app.assist.AssistContent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.KeyboardShortcutGroup;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;

import com.chaodriod.common.utils.ALog;

import java.util.List;

/**
 * Created by CHEN on 2018/1/17.
 */

public class LoggerActivity extends FragmentActivity {

    public void log(String msg) {
        ALog.e(msg);
    }

    /********************************主要生命周期********************************/

    @Override
    public void onAttachFragment(Fragment fragment) {
        super.onAttachFragment(fragment);
        log("onAttachFragment: "+fragment);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        log("onCreate");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        log("onCreate_persistentState");
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        log("onCreateView");
        return super.onCreateView(name, context, attrs);
    }

    @Override
    public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
        log("onCreateView_parent");
        return super.onCreateView(parent, name, context, attrs);
    }

    @Override
    public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
        super.onWindowAttributesChanged(params);
        log("onWindowAttributesChanged");
    }



    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        log("onRestoreInstanceState");
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onRestoreInstanceState(savedInstanceState, persistentState);
        log("onRestoreInstanceState");
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        log("onPostCreate");
    }

    @Override
    public void onPostCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onPostCreate(savedInstanceState, persistentState);
        log("onPostCreate");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        log("onRestart");
    }

    @Override
    public void onLocalVoiceInteractionStarted() {
        super.onLocalVoiceInteractionStarted();
        log("onLocalVoiceInteractionStarted");
    }

    @Override
    public void onLocalVoiceInteractionStopped() {
        super.onLocalVoiceInteractionStopped();
        log("onLocalVoiceInteractionStopped");
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        log("onSaveInstanceState");
    }

    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        log("onUserLeaveHint");
    }

    @Override
    public void onProvideAssistData(Bundle data) {
        super.onProvideAssistData(data);
        log("onProvideAssistData");
    }

    @Override
    public void onProvideAssistContent(AssistContent outContent) {
        super.onProvideAssistContent(outContent);
        log("onProvideAssistContent");
    }

    @Override
    public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu, int deviceId) {
        super.onProvideKeyboardShortcuts(data, menu, deviceId);
        log("onProvideKeyboardShortcuts");
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        log("onTrimMemory");
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        log("onWindowFocusChanged");
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        log("onDetachedFromWindow");
    }

    @Override
    public Uri onProvideReferrer() {
        log("onHiddenChanged");
        return super.onProvideReferrer();
    }

    @Override
    public void onVisibleBehindCanceled() {
        super.onVisibleBehindCanceled();
        log("onVisibleBehindCanceled");
    }

    @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();
        log("onEnterAnimationComplete");
    }

    /**
     * 在清单文件中Activity标签下可以指定参数android：ConfigChanges，用于捕获手机状态的改变。
     * 当所指定属性(Configuration Changes)发生改变时，会调用onConfigurationChanged()
     * 如果改变的属性没有在清单文件中指定就会销毁当前Activity，重新创建一个
     * 具体属性如下：
     * "mcc"	        国际移动用户识别码所属国家代号改变了-----  sim被侦测到了，去更新mcc
     * mcc是移动用户所属国家代号
     * "mnc"	        国际移动用户识别码的移动网号码改变了------ sim被侦测到了，去更新mnc
     * MNC是移动网号码，最多由两位数字组成，用于识别移动用户所归属的移动通信网
     * "locale"	        地址改变了-----用户选择了一个新的语言会显示出来
     * "touchscreen"	触摸屏是改变了------通常是不会发生的
     * "keyboard"	    键盘发生了改变----例如用户用了外部的键盘
     * "keyboardHidden"	键盘的可用性发生了改变
     * "navigation"	    导航发生了变化-----通常也不会发生
     * "screenLayout"	屏幕的显示发生了变化------不同的显示被激活
     * "fontScale"	    字体比例发生了变化----选择了不同的全局字体
     * "uiMode"	        用户的模式发生了变化
     * "orientation"	屏幕方向改变了
     * "screenSize"	    屏幕大小改变了，屏幕旋转也会导致screenSize改变
     * "smallestScreenSize"	屏幕的物理大小改变了，如：连接到一个外部的屏幕上
     */
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        log("onConfigurationChanged");
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        log("onDestroy");
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        log("onLowMemory");
    }

    @Override
    protected void onPause() {
        super.onPause();
        log("onPause");
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        log("onNewIntent");
    }

    @Override
    public void onStateNotSaved() {
        super.onStateNotSaved();
        log("onStateNotSaved");
    }

    @Override
    protected void onResume() {
        super.onResume();
        log("onResume");
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        log("onPostResume");
    }

    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        log("onResumeFragments");
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        log("onSaveInstanceState");
    }

    @Override
    protected void onStart() {
        super.onStart();
        log("onStart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        log("onStop");
    }

    @Override
    public Object onRetainCustomNonConfigurationInstance() {
        log("onRetainCustomNonConfigurationInstance");
        return super.onRetainCustomNonConfigurationInstance();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        log("onRequestPermissionsResult");
    }

    @Nullable
    @Override
    public CharSequence onCreateDescription() {
        log("onCreateDescription");
        return super.onCreateDescription();
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        log("onContentChanged");
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        log("onAttachedToWindow");
    }

    @Override
    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
        super.onApplyThemeResource(theme, resid, first);
        log("onApplyThemeResource");
    }

    @Override
    public void onActivityReenter(int resultCode, Intent data) {
        super.onActivityReenter(resultCode, data);
        log("onActivityReenter");
    }

    @Override
    protected void onChildTitleChanged(Activity childActivity, CharSequence title) {
        super.onChildTitleChanged(childActivity, title);
        log("onChildTitleChanged");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        log("onActivityResult: requestCode = " + requestCode + ", resultCode = " + resultCode + ", data = " + data);
    }

    /**
     * 触摸事件：以下事件不一定会回调 Super()
     */

    @Override
    public void onUserInteraction() {
        super.onUserInteraction();
        log("onUserInteraction");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        log("onKeyDown");
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
        log("onKeyLongPress");
        return super.onKeyLongPress(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        log("onKeyUp");
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
        log("onKeyMultiple");
        return super.onKeyMultiple(keyCode, repeatCount, event);
    }

    @Override
    public boolean onKeyShortcut(int keyCode, KeyEvent event) {
        log("onKeyShortcut");
        return super.onKeyShortcut(keyCode, event);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        log("onBackPressed");
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        log("onTouchEvent");
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onTrackballEvent(MotionEvent event) {
        log("onTrackballEvent");
        return super.onTrackballEvent(event);
    }

    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        log("onGenericMotionEvent");
        return super.onGenericMotionEvent(event);
    }

    /**
     * 多窗口模式
     */
    @Override
    public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
        super.onMultiWindowModeChanged(isInMultiWindowMode);
        log("onMultiWindowModeChanged");
    }
    @Override
    public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
        super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig);
        log("onMultiWindowModeChanged");
    }

    /**
     * 画中画模式
     */
    @Override
    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
        super.onPictureInPictureModeChanged(isInPictureInPictureMode);
        log("onPictureInPictureModeChanged");
    }
    @Override
    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
        super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
        log("onPictureInPictureModeChanged");
    }
}
